﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Bookvar.UI.Converters;

namespace Bookvar.UI
{
    internal static class BindingHelper
    {
        public static void AddDependecyPropertyBindings( MultiBinding multiBinding, object source,
                                                         params DependencyProperty[] properties )
        {
            foreach ( DependencyProperty property in properties )
            {
                Binding binding = new Binding();
                binding.Path = new PropertyPath( property );
                binding.Source = source;

                multiBinding.Bindings.Add( binding );
            }
        }

        public static BindingBase CreateControlCenterBinding( FrameworkElement source )
        {
            MultiBinding binding = new MultiBinding();
            binding.Converter = ControlCenterConverter.Instance;

            AddDependecyPropertyBindings( binding, source,
                                          FrameworkElement.ActualWidthProperty, FrameworkElement.ActualHeightProperty,
                                          Canvas.LeftProperty, Canvas.TopProperty );

            return binding;
        }

        public static BindingBase CreateToggleButtonBinding( TopicContentPresenter source )
        {
            MultiBinding binding = new MultiBinding();
            binding.Converter = ToggleChildrenCenterConverter.Instance;
            binding.ConverterParameter = source;

            AddDependecyPropertyBindings( binding, source,
                                          UIElement.VisibilityProperty, Canvas.LeftProperty,
                                          Canvas.TopProperty, FrameworkElement.ActualWidthProperty,
                                          FrameworkElement.ActualHeightProperty );

            return binding;
        }
    }
}